package net.hn.hnms.biz.emgcy.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.emgcy.domain.EmergencyTrainingPo;
import net.hn.hnms.biz.emgcy.service.EmergencyTrainingService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: EmergencyTrainingController
 * @Description 培训考评Controller
 * @Author 王龙
 * @Date 2022-10-14
 * @Version 0.1
 */
@Api(value = "应急管理-预案培训控制器", tags = {"-预案培训"})
@RestController
@RequestMapping("emergencyTraining")
public class EmergencyTrainingController {
    @Resource
    private EmergencyTrainingService emergencyTrainingService;
    @ApiOperation("培训考评-添加")
    @PostMapping("/add")
    public R add(@RequestBody EmergencyTrainingPo emergencyTrainingPo){
        Boolean is=emergencyTrainingService.add(emergencyTrainingPo);
        if (is) {
            return R.ok("添加成功");
        }
        return R.fail("添加失败");
    }
    @ApiOperation("培训考评-列表")
    @GetMapping("/pageList")
    @AutoSetMineCode
    public R<ResponsePage<EmergencyTrainingPo>> pageList(PageQuery pageQuery, String name,@ApiParam(value = "煤矿编码") String mineCode){
        ResponsePage<EmergencyTrainingPo> page =emergencyTrainingService.pageList(pageQuery,name,mineCode);
        return R.ok(page);
    }

    @ApiOperation("培训考评-根据ID查看详情")
    @GetMapping("/{id}")
    public R<EmergencyTrainingPo> getByID(@PathVariable(value = "id")String id){
        EmergencyTrainingPo emergencyTrainingPo = emergencyTrainingService.getByID(id);

        return R.ok(emergencyTrainingPo);
    }

    @ApiOperation("培训考评-根据ID删除")
    @DeleteMapping("/{id}")
    public R<List<EmergencyTrainingPo>> delete(@PathVariable(value = "id") String id) {

        Boolean is = emergencyTrainingService.delete(id);
        if (is) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }


    @ApiOperation("培训考评-根据ID批量删除")
    @DeleteMapping("/delete")
    public R<List<EmergencyTrainingPo>> deleteAll(@RequestBody List<String> idList) {

        Boolean is = emergencyTrainingService.deleteAll(idList);
        if (is) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
}
